package com.wudao.ncmplay.resolver;

import com.wudao.ncmplay.config.NcmProperties;
import com.wudao.ncmplay.util.StringUtil;
import org.springframework.web.servlet.LocaleResolver;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @Description 语言刷新类
 *
 * @author Lin Heng
 * @Date  2022/6/11
 **/
public class NcmLocaleResolver implements LocaleResolver
{
    @Resource
    private NcmProperties ncmProperties;

    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest)
    {
        String lang = httpServletRequest.getParameter("lang");
        Locale locale = Locale.getDefault();
        if(StringUtil.isNullOrEmpty(lang)){
            lang = ncmProperties.getLang();
        }
        String[] language = lang.split("_");
        locale = new Locale(language[0], language[1]);
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale)
    {

    }
}
